package com.sinux.sshUser.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "sys_user")
@DynamicInsert(true)
@DynamicUpdate(true)
public class User {
	private String uid;
	private String uname;
	private String email;
	private String phone;
	private String logname;
	private String pwd;
	private int ustate; //状态
	private String cdate;
	
	@JsonIgnore
	private Set<Role> roles = new HashSet<Role>();
	@JsonIgnore
	private Set<Department> departs=new HashSet<Department>();
	
	//nullable：表示该字段是否允许为null。默认为true  
	//unique：表示该字段是否是唯一标识。默认为false  
	@Id
	@Column(name = "u_id", unique = true, nullable = false, length = 64)
	public String getUid() {
		return uid;
	}
	public void setUid(String uid) {
		this.uid = uid;
	}
	
	@Column(name = "u_name",  nullable = false, length = 64)
	public String getUname() {
		return uname;
	}
	public void setUname(String uname) {
		this.uname = uname;
	}
	
	@Column(name = "email",  nullable = false, length = 64)
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	
	@Column(name = "log_name",  nullable = false, length = 64)
	public String getLogname() {
		return logname;
	}
	public void setLogname(String logname) {
		this.logname = logname;
	}
	
	@Column(name = "pwd", nullable = false, length = 64)
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	
	@Column(name = "phone",  nullable = true, length = 64)
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	@Column(name = "ustate",  nullable = false, length = 64)
	public int getUstate() {
		return ustate;
	}
	public void setUstate(int ustate) {
		this.ustate = ustate;
	}
	
	@Column(name = "cdate",  nullable = true, length = 64)
	public String getCdate() {
		return cdate;
	}
	public void setCdate(String cdate) {
		this.cdate = cdate;
	}
	
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(
		name = "re_user_role", //关联表名称
		joinColumns = { @JoinColumn(name = "u_id", nullable = false, updatable = false) }, 
		inverseJoinColumns = { @JoinColumn(name = "ro_id", nullable = false, updatable = false)})
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(
		name="re_user_department",
		joinColumns={@JoinColumn(name="u_id",nullable=false,updatable=false)},
		inverseJoinColumns={@JoinColumn(name="de_id",nullable=false,updatable=false)})
	public Set<Department> getDeparts() {
		return departs;
	}
	public void setDeparts(Set<Department> departs) {
		this.departs = departs;
	}
	
	

}
